package com.aaa.controller;

import com.aaa.entity.LayData;
import com.aaa.entity.MyPage;
import com.aaa.entity.Role;
import com.aaa.service.RoleService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    /**
     * 查询全部角色的名字
     * @return
     */
    @GetMapping("findRole")
    public LayData findRoleName(){
        List<Role> roleName = roleService.findRoleName();
        LayData layData = new LayData(roleName);
        return layData;
    }
    /**
     * 查询角色信息
     */
    @ResponseBody
    @RequestMapping("findAllRole")
    public LayData findAllRole(MyPage myPage){
        PageInfo all = roleService.selectAll(myPage);
        LayData layData = new LayData(all);
        return layData;
    }
    /**
     *添加角色
     */
    @PostMapping("/addRole")
    @ResponseBody
    public LayData addRole(Role role){
        Boolean status = roleService.addRole(role);
        return new LayData(status);
    }
    /**
     *判断角色是否存在
     */
    @PostMapping("/checkName{rolename}")
    @ResponseBody
    public LayData checkName(@PathVariable String rolename){
        Boolean isNo = roleService.checkName(rolename);
        return new LayData(isNo);
    }

    /**
     * 删除
     */
    @PostMapping("/delRole")
    @ResponseBody
    public LayData del(Role role) {
        Boolean isNo = roleService.delRole(role);
        return new LayData(isNo);
    }
}
